class Solution:
  def exchange(self, nums: list) -> list:
    ptr_i, ptr_j = 0, len(nums) - 1
    while ptr_i < ptr_j:
      if nums[ptr_i] & 1:
        ptr_i = ptr_i + 1
      if not nums[ptr_j] & 1:
        ptr_j = ptr_j - 1
      else:
        nums[ptr_i], nums[ptr_j] = nums[ptr_j], nums[ptr_i]
    return nums


'''
STATUS: LEARNT
TRIES:  N/A
TIME:   84 MS
MEMORY: 17.9 MB
'''
if __name__ == '__main__':
  solution = Solution()
  print(solution.exchange([1, 2, 3, 4]))
